#include "StdAfx.h"
#include "XtremChildFrame.h"
#include "XtremeMDIFrameWnd.h"


CXtremChildFrame::CXtremChildFrame(void)
	: pTabControl(NULL)
	, pRibbonBar(NULL)
{
}


CXtremChildFrame::~CXtremChildFrame(void)
{
	CXtremeMDIFrameWnd* pMainFrame = (CXtremeMDIFrameWnd*)AfxGetMainWnd();	
	if(pMainFrame->GetMDIFrameShowType() == 0)
	{
		return;
	}
	CXTPCommandBars* pCommandBars = pMainFrame->GetCommandBars();

	CXTPRibbonBar* pRibbonBar = (CXTPRibbonBar*)pCommandBars->GetAt(0);
	int count = pRibbonBar->GetTabCount();
	for(int i = 1 ; i< count; ++i)
	{
		CXTPRibbonTab* pTab = pRibbonBar->GetTab(i);
		if(pTab == pTabControl)
		{
			pRibbonBar->RemoveTab(i);
			break;
		}
	}
}

BEGIN_MESSAGE_MAP(CXtremChildFrame, CMDIChildWnd)
	ON_WM_CREATE()
	ON_WM_SIZE()
//	ON_WM_ACTIVATE()
//ON_WM_CLOSE()
END_MESSAGE_MAP()


int CXtremChildFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	LoadIcons();

	CreateRibbonBar();

	CreateStatusBar();

	EnableOffice2007Frame(this, ((CXTPMDIFrameWnd*)GetParentFrame())->GetCommandBars()->GetPaintManager());
	
	return 0;
}


void CXtremChildFrame::OnSize(UINT nType, int cx, int cy)
{
	if((cx ==100) && (cy == 100))
	{
		if( this->GetSafeHwnd() != NULL)
		{			
			//CMDIFrameWnd   *pFrame=(CMDIFrameWnd*)this->GetParent()->GetParent(); 
			//CRect   rc  ; 
			//::GetWindowRect(pFrame->m_hWndMDIClient,&rc); 
			//this->MoveWindow(-1,-1,rc.Width()*2+2,rc.Height()+2);
			this->ShowWindow(SW_SHOWMAXIMIZED);
			this->MDIMaximize();
		}
	}
	else
	{
		CMDIChildWnd::OnSize(nType, cx, cy);
	}
}


BOOL CXtremChildFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Add your specialized code here and/or call the base class
	
	cs.x = 
	cs.y = 0;
	
	cs.cx = 
	cs.cy = 32767;
	cs.style^=WS_TILEDWINDOW;
	//cs.style^=WS_CAPTION;
	//cs.style|=WS_CLIPCHILDREN|WS_CLIPSIBLINGS|WS_POPUP;

	if( !CMDIChildWnd::PreCreateWindow(cs) )
		return FALSE;

	cs.style |= WS_CLIPCHILDREN;
	
	cs.style = WS_CHILD | WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU
		| FWS_ADDTOTITLE | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;

	return TRUE;
}


// SetInitRect
void CXtremChildFrame::SetInitRect(const CRect & rect)
{
	//m_MdiClientRect = rect;
	//this->MoveWindow(-1,-1,rect.Width()+2,rect.Height()+2);
}


bool CXtremChildFrame::CreateRibbonBar(void)
{
	return true;
}
bool CXtremChildFrame::CreateStatusBar(void)
{
	return true;
}

void CXtremChildFrame::LoadIcons()
{
}


CXTPRibbonTab* CXtremChildFrame::GetRibbonTab()
{
	return pTabControl;
}

CXTPRibbonBar* CXtremChildFrame::GetRibbonBar()
{
	return pRibbonBar;
}

int CXtremChildFrame::UpdateRibbonTab()
{	
	CXtremeMDIFrameWnd* pMainFrame = (CXtremeMDIFrameWnd*)AfxGetMainWnd();	
	CXTPCommandBars* pCommandBars = pMainFrame->GetCommandBars();
	if(pRibbonBar == NULL)
	{
		return 0;
	}
	int count = pRibbonBar->GetTabCount();
	for(int i = 1 ; i< count; ++i)
	{
		CXTPRibbonTab* pTab = pRibbonBar->GetTab(i);
		if(pTab == pTabControl)
		{
			pRibbonBar->SetCurSel(i);
		}
	}
	return 1 ;
}

void CXtremChildFrame::ActivateFrame(int nCmdShow)
{
	// TODO: Add your specialized code here and/or call the base class
	if (GetParent()->GetWindow(GW_CHILD) == this)
	{
		nCmdShow = SW_SHOWMAXIMIZED;
	}

	CMDIChildWnd::ActivateFrame(nCmdShow);
}
